<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    li {
      list-style: none;
    }

    a {
      color: inherit;
      text-decoration: none;
    }

    .wrap {
      width: 600px;
      margin: 100px auto;
    }

    .wrap .navBar {
      display: flex;
    }

    .wrap .navBar li {
      flex: 1;
      text-align: center;
      line-height: 45px;
      border: 1px solid #333;
    }

    .wrap .navBar .active {
      background-color: #f00;
      color: #fff;
    }

    /* 和li相邻的li  => 除第一个以外所有的li */
    .wrap .navBar li+li {
      border-left: 0;
    }

    .tabBar {
      height: 400px;
      box-sizing: border-box;
    }

    .tabBar .part {
      height: 100%;
      text-align: center;
      line-height: 400px;
      border: 1px solid #333;
      display: none;
    }

    .tabBar .show {
      display: block;
    }
  </style>
</head>

<body>
  <div class="wrap">
    <ul class="navBar">
      <li class="active">tab_01</li>
      <li>tab_02</li>
      <li>tab_03</li>
      <li>tab_04</li>
      <li>tab_05</li>
      <li>tab_06</li>
    </ul>
    <div class="tabBar">
      <div class="part show">part_01</div>
      <div class="part">part_02</div>
      <div class="part">part_03</div>
      <div class="part">part_04</div>
      <div class="part">part_05</div>
      <div class="part">part_06</div>
    </div>
  </div>
</body>
<script>
  var navBar = document.getElementsByClassName("navBar")[0];
  var liList = navBar.getElementsByTagName("li");

  var partList = document.querySelectorAll(".tabBar .part");



  // 循环绑定事件
  // for(var i = 0;i< liList.length;i++){
  //     var li = liList[i];
  //     li.setAttribute("index",i);
  //     li.onclick = function(){
  //         var index = this.getAttribute("index");

  //         // 每次点击  => 把所有的li的活跃样式(active)清除 ,所有的part盒子隐藏
  //         for(var j = 0; j < liList.length;j++){ 
  //             liList[j].className = "";
  //             partList[j].classList.remove("show");
  //         }

  //         // 把当前点击的元素变为活跃状态   => 对应盒子显示
  //         this.className = "active";
  //         partList[index].classList.add("show");

  //     }
  // }


  for (let i = 0; i < liList.length; i++) {
    let li = liList[i];
    li.onclick = function () {

      // 每次点击  => 把所有的li的活跃样式(active)清除 ,所有的part盒子隐藏
      for (var j = 0; j < liList.length; j++) {
        liList[j].className = "";
        partList[j].classList.remove("show");
      }

      // 把当前点击的元素变为活跃状态   => 对应盒子显示
      liList[i].className = "active";
      partList[i].classList.add("show");

    }
  }



</script>

</html>